#lang r5rs
(define (conss x y)
  (lambda (m) (m x y)))
(define (cars z)
  (z (lambda (x y) x)))
(define (cdrs z)
  (z (lambda (x y) y)))


(define (consa x y)
  (define (expt below up result)
    (if (= up 0)
        result
        (expt below (- up 1) (* result below))))
  (* (expt 2 x 1) (expt 3 y 1)))
;(consa x y) = 2^x * 3 ^y
;log2(2^x * 3^y) = A -> x + y* log2(3) = A 
;log3(2^x * 3^y) = B -> log3(2) x + y  = B

(define (lognn x y)
  (/ (log y) (log x)))
(define (cara x)
  (define (devide-x x from)
    (if (= (remainder (- x (* (lognn 2 3) from)) 1) 0)
        (- x (* (lognn 2 3) from))
        (devide-x x (+ from 1))))
  (devide-x x 0))
(define (cdr x)
  (define (devide-y x from)
    (if (= (remainder (- x (* (lognn 2 3) from)) 1) 0)
        from
        (devide-y x (+ from 1))))
  (devide-y x 0))

(define (acc n) (+ 1 n))
(define zero (lambda (f) (lambda (x) x)))
(define (add-1 n) (lambda (f) (lambda (x) (f ((n f) x)))))
(define (church-display church-num)
  (display ((church-num acc) 0)))
(define (plus n m)
  (lambda (f) (lambda (x) ((n f) ((m f) x)))))
(church-display (plus (add-1 zero) (add-1 zero)))